package com.hunt.service.impl;
import com.hunt.model.entity.EastMoneySpider;
import com.hunt.service.EastMoneySpiderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author sjs
 * @className
 * @description
 * @date 2020/10/29
 */
@Service
@Transactional
public class EastMoneySpiderServiceImpl implements EastMoneySpiderService {
    private static final String table  = "northCrawler";

    @Autowired
    private MongoTemplate northFundMongoTemplate;

    @Override
    public EastMoneySpider getEastSpider() {
        Query query = new Query();
        query.with(new Sort(Sort.Direction.DESC,"_id"));//发布日期排序
        query.limit(1);
        EastMoneySpider em=northFundMongoTemplate.find(query,EastMoneySpider.class,table).get(0);
         double  NetCapitalInflow= Double.parseDouble(em.getNetCapitalInflow());
        NetCapitalInflow = (double) Math.round(NetCapitalInflow * 100) / 100;
        em.setNetCapitalInflow(String.valueOf(NetCapitalInflow));
        //返回的北向保留两位小数
        return  em;
    }
}
